﻿using System;
using System.Web;
using Framework;

namespace Enterprise.Admin.Handle
{
    /// <summary>
    /// 添加产品图片
    /// </summary>
    public partial class AddProductImage : AdminBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            object result;
            try
            {
                var file = Request.Files["Filedata"];
                if (file == null)
                {
                    Json(new { state = false, message = "上传文件不能为空！" });
                }
                var filedata = new HttpPostedFileWrapper(Request.Files["Filedata"]);
                var productId = Fq("CoProductId").SafeToInt();
                var isCover = Fq("CoIsCover").SafeToBool();
                var productImageService = new ProductImageService();
                var ur = productImageService.Add(productId, isCover, filedata);
                result = (new { state = true, message = "上传成功！", fileName = ur[1], id = ur[0], thumFileName = ur[2] });
            }
            catch (Exception ex)
            {
                result = (new { state = false, message = ex.Message });
            }
            Json(result);

        }
    }
}